package com.kimoge.spring6.resources.resourceattribute;

import org.springframework.core.io.Resource;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author kimoge
 * @date 2025/8/30
 * @description 创建依赖注入类，定义属性与方法
 */
public class ResourceBean {
    private Resource resource;


    public Resource getResource() {
        return resource;
    }

    public void setResource(Resource resource) {
        this.resource = resource;
    }

    public void print() {
        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());

        try {
            InputStream inputStream = resource.getInputStream();
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes);
            System.out.println(new String(bytes));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
